package br.com.imob.service;

import java.util.List;

import org.apache.log4j.Logger;

import br.com.imob.collector.GenericParser;
import br.com.imob.exception.ParserException;
import br.com.imob.model.ImobItem;
import br.com.imob.solr.SolrService;

public class ImobServiceImpl implements ImobService {

	private static final Logger log = Logger.getLogger( ImobServiceImpl.class );
	
	private GenericParser multiParser;
	private SolrService solrService;

	public void updateImobs() {

		log.info( "Updating imobs... " );
		
		// Update Multi
		try {
			
			List<ImobItem> itemsMulti = multiParser.collectAllItems();
			solrService.addItems( itemsMulti );
			
		} catch (ParserException e) {
			e.printStackTrace();
			log.error( ">> Error on Multi Parser - check it! << ");
		}
		
		// Update next imob...
		
		log.info( "Imobs updated successfully!" );

	}
	
	public List<ImobItem> selectImobs(int first, int last, ImobItem criteria) {
		return solrService.selectItems(criteria, first, last);
	}
	

	public GenericParser getMultiParser() {
		return multiParser;
	}

	public void setMultiParser(GenericParser multiParser) {
		this.multiParser = multiParser;
	}

	public SolrService getSolrService() {
		return solrService;
	}

	public void setSolrService(SolrService solrService) {
		this.solrService = solrService;
	}

	

}
